//
//  QLMNormalViewController.m
//  Xiaomakuaixiu
//
//  Created by 邬俊涛 on 2018/3/9.
//  Copyright © 2018年 hwd. All rights reserved.
//

#import "QLMNormalViewController.h"
#import "QLMNorInvoiceTabCell.h"

@interface QLMNormalViewController ()<UITableViewDelegate,UITableViewDataSource>{
    QLMCustomTipView *tipView;
}

@end

@implementation QLMNormalViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
//    self.view.backgroundColor=[UIColor whiteColor];
    
    CGRect tabFrame = CGRectMake(0, 1, kScreen_width, kScreen_height-41-QLM_StatusBarAndNavigationBarHeight-IOS11_OR_LATER_SPACE(34));
    
    _normaltableview=[[UITableView alloc] initWithFrame:tabFrame style:UITableViewStylePlain];
    _normaltableview.backgroundColor=[UIColor clearColor];
    _normaltableview.delegate=self;
    _normaltableview.dataSource=self;
    _normaltableview.separatorStyle=UITableViewCellSeparatorStyleNone;
    _normaltableview.showsVerticalScrollIndicator=NO;
    _normaltableview.showsHorizontalScrollIndicator=NO;
    _normaltableview.tableFooterView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreen_width, 0.01)];
    _normaltableview.tableHeaderView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreen_width, 0.01)];
    [self.view addSubview:_normaltableview];
    
    if (@available(iOS 11.0, *)) {
        _normaltableview.contentInsetAdjustmentBehavior=UIScrollViewContentInsetAdjustmentNever;
    } else {
        // Fallback on earlier versions
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    
    tipView=[QLMCustomTipView sharedInstance];
    tipView.hidden = YES;
    [self.view addSubview:tipView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.001;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return nil;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 150;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (_invoiceNorModel.invoiceNorArrModel.count==0) {
        tipView.hidden = NO;
        return 0;
    }
    tipView.hidden = YES;
    return 1;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return _invoiceNorModel.invoiceNorArrModel.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    QLMNorInvoiceTabCell *normalCell=[QLMNorInvoiceTabCell cellWithTableView:tableView];
    normalCell.selectionStyle=UITableViewCellSelectionStyleNone;
    normalCell.backgroundColor=[UIColor clearColor];
    
    QLMInvoiceNorInfoModel *norInfoModel=[[QLMInvoiceNorInfoModel alloc] initWithDictionary:_invoiceNorModel.invoiceNorArrModel[indexPath.section] error:nil];
    normalCell.taxNoLabel.text=[NSString stringWithFormat:@"%@",norInfoModel.taxNo];
    normalCell.companyNameLabel.text=[NSString stringWithFormat:@"%@",norInfoModel.companyName];
    return normalCell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

@end
